Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

[Core] Change libs to netstandard #687

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions TeleSharp.TL/TLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ public static class TLContext

public static void Init()
{
Types = new Dictionary<int, Type>();
Types = (from t in Assembly.GetExecutingAssembly().GetTypes()
where t.IsClass && t.Namespace.StartsWith("TeleSharp.TL")
where t.IsSubclassOf(typeof(TLObject))
where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
Types.Add(481674261, typeof(TLVector<>));
try
{
Types = new Dictionary<int, Type>();
Types = (from t in Assembly.GetExecutingAssembly().GetTypes()
where t.IsClass && t.Namespace.StartsWith("TeleSharp.TL")
where t.IsSubclassOf(typeof(TLObject))
where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
Types.Add(481674261, typeof(TLVector<>));
}
catch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exception did you receive here? You should add the exception type, as putting "catch-all" blocks like this is quite dangerous.

Copy link
Author

@LORDofDOOM LORDofDOOM Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometime the error that @Jarzamendia describes top

I recive An item with the same key has already been added. Key: 481674261 when I use this dll's. :(

This happens if the assembly is loaded twice e.g. from any dependency injection. This only happens if 481674261 is already added - A global try/catch is OK here IMHO

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A global catch is never OK (the only exception is in the entry point of your application, for logging and bug-auto-submission purposes). When you're dealing with certain exception of type X, you need to use that type X in the code because the future developers need to know what was happening, what were you trying to fix. Please add the type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add proper method to prevent double adding type

{

}
}
public static Type getType(int Constructor)
{
Expand Down